package it.massetti.scoponescientifico.game;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Deck {
	List<Card> deck = new ArrayList<Card>();
	
	public Deck () {
		int number;
		int suit;
		for(number=1; number<=10; number++) {
			for(suit=1; suit<=4; suit++) {
				deck.add(new Card(getNumber(number), getSuit(suit))); 
			}
		}
		Collections.shuffle(deck);
	}
	
	/**
	 * Get the first card from the deck
	 * @return card
	 */
	Card getFirstCard () {
		Card card = deck.get(1);
		deck.remove(1);
		return card;
	}
	
	/**
	 * Sum a list of cards
	 * @param a list of cards
	 * @return sum of the cards
	 */
	int sumCards(List<Card> cards) {
		int sum = 0;
		for(Card current : cards) {
			sum=sum+current.getNumber();
		}
	return sum;
	}
	
	/**
	 * Get the number of a card
	 * @param value
	 * @return Number
	 */
	Number getNumber (int value) {
		switch (value) {
		case 1:
			return Number.ACE;
		case 2:
			return Number.TWO;
		case 3:
			return Number.THREE;
		case 4:
			return Number.FOUR;
		case 5:
			return Number.FIVE;
		case 6:
			return Number.SIX;
		case 7:
			return Number.SEVEN;
		case 8:
			return Number.JACK;
		case 9:
			return Number.QUEEN;
		case 10:
			return Number.KING;
		}
		return null;
	}
	
	/**
	 * Get the Suit of a card
	 * @param value
	 * @return suit
	 */
	Suit getSuit(int value) {
		switch (value) {
		case 1:
			return Suit.HEARTS;
		case 2:
			return Suit.DIAMONDS;
		case 3:
			return Suit.CLUBS;
		case 4:
			return Suit.SPADES;
		} 
		return null;
	}
}
